<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8" />
    <title>下载中心</title>
    <!--CSS-->
    <link rel="stylesheet" type="text/css" media="all" href="/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" media="all" href="/css/global.css"/>
    <!--JavaScript-->
    <script type="text/javascript" src="/layui/layui.all.js"></script>
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/js/myJs.js"></script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <div class="layui-col-sm12">
            <div style="width: 80px; font-weight: bolder; font-size: large; margin-top: 20px; margin-left: auto; margin-right: auto">下载列表</div>
            <table class="layui-table" id="filetable" lay-filter="table"></table>
        </div>
    </div>
</div>

<!--Footer-->
<div class="fly-footer">
    <p><a target="_blank">我打 - 下载专区</a> 2018</p>
</div>
<script >

    layui.use('table', function(){
        var table = layui.table,$ = layui.jquery;
        table.render({   //方法渲染
            elem: '#filetable'
            ,url:'/download/getFileForPaging'
            ,cellMinWidth: 80
            ,page: true //开启分页
            ,cols: [[
                {field:'id', title: 'ID', align:'center', width: 60}
                ,{field:'fileName', title: '文件名', align:'center', minWidth: 180 }
                ,{field:'fileUrl', title: '下载链接', align:'center', width:720}
                ,{field:'fileVersion', title: '文件版本', align:'center', width: 220}
                ,{field:'filePlat', title: '支持平台', align:'center', width: 200}
                ,{fixed: 'right', width:200, align:'center', toolbar: '#downloadDemo'}
            ]],
            request: {
                pageName: 'pageNumber', //页码的参数名称，默认：page
                limitName: 'pageSize' //每页数据量的参数名，默认：limit
            },
            response: {
                countName: 'total', //数据总数的字段名称，默认：count
          dataName: 'rows' //数据列表的字段名称，默认：data
            }
        });

        table.on('tool(table)', function(obj){
            var data = obj.data;
            if(obj.event === 'xiazai'){
                var url = "/download/file";
                var  fileName = data.fileUrl;
                var form = $("<form></form>").attr("action", url).attr("method", "get");
                form.append($("<input></input>").attr("type", "hidden").attr("name", "fileName").attr("value", fileName));
                form.appendTo('body').submit().remove();
            }
        })
    });
</script>

<script type="text/html" id="downloadDemo">
    <a class="layui-btn layui-btn-xs" lay-event="xiazai">点击下载</a>
</script>
</body>
</html>